function[]=ksregress(X,Y,f,prm)
%KSREGRESS  kernel regression
%
%  ksregress(x,y,f,prom)
%     [x,y] ... data set, x - design points (must be equidistant!)
%                         y - measurements
%      f ...... string, regression function (optional: default=[]=we don't know regression function)
%      prom ... string, variable of regression function (optional: default='x')
%
% (C) Jan Kolacek, Masaryk University (Czech Republic)

w=which('ksregress.m');
w(end-11:end)=[];
addpath(w);
addpath([w,'/regress']);
addpath([w,'/quality']);
addpath([w,'/distrib']);
addpath([w,'/bivardens']);
addpath([w,'/dens']);
addpath([w,'/dens/base']);
addpath([w,'/dens/functions']);

if nargin<1
    br=get(0,'DefaultFigureColor');
    %%v4colset;
    save v.mat br;
    
    callbackStr=['set(gcf,''CloseRequestFcn'',''closereq'');',...
        'load v.mat;if br~=[0 0 0] v5colset;end;', ...
        'clear;load puvprom;close(findobj(0,''Tag'',''kclos''));',...
        'delete v.mat;delete puvprom.mat;delete(gcf);clear *_def;'];
    
    crStr= 'save puvprom;';
    
    figure( ...
        'Visible','on', ...
        'Name','DATA LOADING', ...
        'CloseRequestFcn',callbackStr,...
        'Units','Normalized',...
        'CreateFcn',crStr,...
        'Tag','defprom',...
        'NumberTitle','off');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.4,.85,.2,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[1 0 0], ...
        'FontSize',0.5,...
        'String','Load Data');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.75,.3,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Select a file to load:');
    
    prom=char(who('-file','puvprom.mat'));
    S=whos('-file','puvprom.mat');
    idtxt=zeros(length(S),1);
    iddbl=zeros(length(S),1);
    for i=1:length(S)
        idtxt(i)=strcmp(S(i).class,'char');
        iddbl(i)=strcmp(S(i).class,'double');
    end
    promtxt=prom(logical(idtxt),:);
    promdbl=prom(logical(iddbl),:);
    rozhtxt='on';
    
    if size(prom,1)<2
        rozh='off';
    else
        rozh='on';
    end
    if or(size(promtxt,1)<1,size(promdbl,1)<2)
        promtxt=char('[]');
        rozhtxt='off';
    end
    
    if size(promdbl,1)<2
        promdbl=char('[]','[]');
    end
%     if size(promdbl,1)==1
%         promdbl=char(promdbl,'[]');
%     end

    % The BROWSE button
    call='uiopen(''LOAD'');prom=char(who);G=get(gcf,''userdata'');';
    call1='if size(prom,1)>1 set([G(1),G(2)],''String'',prom);set([G(1),G(2),G(4),G(5)],''Enable'',''on'');end;';
    call2='G=get(gcf,''userdata'');ind=get(G(1),''Value'');prom=get(G(1),''String'');x_def=eval(prom(ind,:));';
    call3='G=get(gcf,''userdata'');ind=get(G(2),''Value'');prom=get(G(2),''String'');y_def=eval(prom(ind,:));';
    call4='G=get(gcf,''userdata'');ind=get(G(4),''Value'');prom=get(G(4),''String'');m_def=eval(prom(ind,:));';
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.4,.8,.1,0.07], ...
        'String','Browse', ...
        'Callback',[call,call1,call2,call3,call4]);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.675,.3,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','OR');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.6,.3,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Make a simulation:');
    
    % The SIMULATION button
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.4,.65,.1,0.07], ...
        'String','Simulation', ...
        'Callback','simulregress');
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.5,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Define the name of independent variable (x):');
    
    xHndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.55,.1,.04], ...
        'String',promdbl, ...
        'FontSize',0.7,...
        'CreateFcn',['x_def=',promdbl(1,:),';'],...
        'Callback',['G=get(gcf,''userdata'');ind=get(G(1),''Value'');prom=get(G(1),''String'');x_def=eval(prom(ind,:));']);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.4,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Define the name of dependent variable (y):');
    
    yHndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.45,.1,.04], ...
        'String',promdbl, ...
        'FontSize',0.7,...
        'Value',2,...
        'CreateFcn',['y_def=',promdbl(2,:),';'],...
        'Callback',['G=get(gcf,''userdata'');ind=get(G(2),''Value'');prom=get(G(2),''String'');y_def=eval(prom(ind,:));']);
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.3,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Write true regression function (if known):');
    
    tHndl=uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.65,.35,.15,.05], ...
        'String','', ...
        'HorizontalAlignment','left',...
        'CreateFcn',['m_def=[];'],...
        'Callback','G=get(gcf,''userdata'');m_def=get(G(3),''String'');');
%        'CreateFcn',['m_def=',promtxt(1,:),';'],...
    
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.22,.6,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','or load the name from a variable: ');
 
    call1='G=get(gcf,''userdata'');ind=get(G(4),''Value'');prom=get(G(4),''String'');';
    call2='m_def=eval(prom(ind,:));set(G(3),''String'',m_def);';
    rHndl=uicontrol( ...
        'Style','popup', ...
        'Enable',rozhtxt,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.7,.28,.1,.04], ...
        'String',promtxt, ...
        'Value',1,...
        'Callback',[call1,call2]);
%        'CreateFcn',['m_def=',promtxt(1,:),';'],...
    
    % The CONTINUE button
    call='save pom.mat x_def y_def m_def;close(gcf);load pom.mat;';
    call1='if ischar(m_def) ksregress(x_def,y_def,m_def); else ksregress(x_def,y_def);end;delete pom.mat;';
    cHndl=uicontrol( ...
        'Style','push', ...
        'Enable',rozh,...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.8,.1,.1,0.07], ...
        'String','Continue', ...
        'Callback',[call,call1]);
    
    
    hndlList=[xHndl,yHndl,tHndl,rHndl,cHndl];
    set(gcf,'UserData',hndlList);
    %set(gcf,'Position',[0 0.0347 1.0000 0.9190]);
    set(gcf,'Position',[0.1059 0.1655 0.7700 0.6898]);
    
else
    
    X1=X;Y1=Y;
    X=X1;Y=Y1;clear X1 Y1;
    x=X(:)';y=Y(:)';
    M=length(x);
    x=linspace(0,(M-1)/M,M);
    if nargin==4
        f(f==prm)='x';
    end;
    krit=max(abs(X(2:M)-X(1:M-1)));
    kritm=min(abs(X(2:M)-X(1:M-1)));
    if abs(krit-kritm)>1e-6
        disp('Design points are not equidistant!');
        krit=max(abs(x(2:M)-x(1:M-1)));
    end;
    %R=fix(101/M);
    %if R>0
    %   xx=min(X):krit/R:max(X)+1e-8;
    %else
    %   xx=X;
    %end;
    xx=X;xp=x;
    save w.mat x y X xx xp;
    br=get(0,'DefaultFigureColor');
    %%v4colset;
    
    callbackStr=['set(gcf,''CloseRequestFcn'',''closereq'');',...
        'load v.mat;if br~=[0 0 0] v5colset;end;', ...
        'clear;load puvprom;close(findobj(0,''Tag'',''kclos''));',...
        'delete v.mat;delete w.mat;delete puvprom.mat;delete(gcf);clear *_def;'];
    
    crStr= 'save puvprom;';
    % unts = get(0,'Units');
    % set(0,'Units','Normalized');
    % scrsz = get(0,'ScreenSize');
    % set(0,'Units',unts);
    %
    C=figure( ...
        'Visible','on', ...
        'Name','KERNEL SMOOTHING', ...
        'CloseRequestFcn',callbackStr,...
        'NumberTitle','off',...
        'CreateFcn',crStr,...
        'Units','Normalized');
    
    save v.mat C br;
    axes( ...
        'Units','normalized', ...
        'Position',[0.08 0.08 0.75 0.87]);
    
    plot(x,y,'x');rr='b--';
    nX=min(X);mX=max(X);
    ff=0;
    if nargin>=3
        if ~isempty(f)
            f=strrep(f,'x','t');
            f=strrep(f,'etp','exp');
            t=linspace(nX,mX,100);
            fx=eval(vectorize(f));
            t=linspace(0,1,100);
            hold on;plot(t,fx,rr);ff=1;
            save v f fx t -append;
        end
    end;
    save v ff rr nX mX -append;
    
    % The CONSOLE frame
    hh=uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.86,0,.15,1], ...
        'BackgroundColor',[0.50 0.50 0.50]);
    
    top=.85;
    % The Zadani button
    call='load v;t=findobj(0,''name'',''EDIT'');';...
        call1=['if isempty(t) prosvit(C);zadani;else set(t,''Visible'',''off'');', ...
        'set(t,''Visible'',''on'');end;'];...
   redHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top,.1,0.1], ...
        'String','Setting', ...
        'Callback',[call,call1]);
    
    % The nw button
    labelStr='NW';
    callbackStr1='load v;load w;[S,yy]=nw(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(10),G(11),G(18)],''enable'',''on'');';
    nwHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.1,.1,0.07], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The cyclic NW button
    labelStr='cyclic';
    callbackStr1='load v;load w;[S,yy]=nwc(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(10),G(11),G(18)],''enable'',''on'');';
    nwcycHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.9,top-.15,.06,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The left NW button
    labelStr='L';
    callbackStr1='load v;load w;[xp,yy]=smnwleft(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    nwLHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.15,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The right NW button
    labelStr='R';
    callbackStr1='load v;load w;[xp,yy]=smnwright(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    nwRHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.96,top-.15,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The ll button
    labelStr='LL';
    callbackStr1='load v;load w;[S,yy]=ll(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(12),G(13),G(18)],''enable'',''on'');';
    llHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.25,.1,0.07], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The cyclic LL button
    labelStr='cyclic';
    callbackStr1='load v;load w;[S,yy]=llc(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(12),G(13),G(18)],''enable'',''on'');';
    llcycHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.9,top-.3,.06,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The left LL button
    labelStr='L';
    callbackStr1='load v;load w;[xp,yy]=smllleft(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    llLHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.3,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The right LL button
    labelStr='R';
    callbackStr1='load v;load w;[xp,yy]=smllright(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    llRHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.96,top-.3,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The GM button
    labelStr='GM';
    callbackStr1='load v;load w;[S,yy]=gm(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(14),G(15),G(18)],''enable'',''on'');';
    gmHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.4,.1,0.07], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The cyclic GM button
    labelStr='cyclic';
    callbackStr1='load v;load w;[S,yy]=gmc(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(14),G(15),G(18)],''enable'',''on'');';
    gmcycHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.9,top-.45,.06,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The left GM button
    labelStr='L';
    callbackStr1='load v;load w;[xp,yy]=smgmleft(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    gmLHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.45,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The right GM button
    labelStr='R';
    callbackStr1='load v;load w;[xp,yy]=smgmright(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    gmRHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.96,top-.45,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The PCH button
    labelStr='PCH';
    callbackStr1='load v;load w;[S,yy]=pch(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(16),G(17),G(18)],''enable'',''on'');';
    pchHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.55,.1,0.07], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The cyclic PCH button
    labelStr='cyclic';
    callbackStr1='load v;load w;[S,yy]=pchc(x,y,n,k,m,h,C);xp=x;save w yy xp -append;G=get(gcf,''userdata'');';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    callbackStr3='if exist(''norminv'') set(G(9),''Enable'',''on'');end;set([G(16),G(17),G(18)],''enable'',''on'');';
    pchcycHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.9,top-.6,.06,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2,callbackStr3]);
    
    % The left PCH button
    labelStr='L';
    callbackStr1='load v;load w;[xp,yy]=smpchleft(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    pchLHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,top-.6,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The right PCH button
    labelStr='R';
    callbackStr1='load v;load w;[xp,yy]=smpchright(x,y,n,k,m,h,C,xp,yy);save w yy xp -append;';
    callbackStr2='if ff==1 hold on;plot(t,fx,rr);hold off;end;yyd=[];save w yyd -append;';
    pchRHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.96,top-.6,.02,0.05], ...
        'String',labelStr, ...
        'Enable','off',...
        'Callback',[callbackStr1,callbackStr2]);
    
    % The SAVE text
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.88,.15,.1,.04], ...
        'BackgroundColor',[0.5 0.5 0.5], ...
        'String','Save Data:');
    
    % The VAR button
    call=['load v;load w; checkLabels = {''Save design points to variable named:'','...
        '''Save transformed design points to variable named:'',',...
        '''Save measurements to variable named:'',',...
        '''Save regression estimates to variable named:'',',...
        '''Save smoothing parameter to variable named:'',',...
        '''Save order (n,k) of used kernel to variable named:'',',...
        '''Save smoothness of used kernel to variable named:''};',...
        'varNames = {''x'',''xx'',''y'',''yy'',''h'',''nk'',''m''};',...
        'items = {xx,x,y,yy,h,[n,k],m}; clear x xx y yy h m;',...
        'if exist(''yyh'',''var'') checkLabels([end+1,end+2]) = {''Save left limits',...
        'of confidence interval to variable named:'',''Save right limits of confidence interval to variance named:''};',...
        'varNames([end+1,end+2])={''conf_l'',''conf_r''};items([end+1,end+2])={yyd,yyh};end;',...
        'save ppp;save pp checkLabels varNames items;clear;load pp;delete pp.mat;',...
        '[hdialog,ok_pressed]=export2wsdlg(checkLabels,varNames,items,''Save Data'');'...
        'if ok_pressed G=get(gcf,''userdata'');set(G(19),''enable'',''on'');',...
        'clear G hdialog ok_pressed checkLabels varNames items;varNames=who;',...
        'save v varNames -append;save(''puvprom'',varNames{:},''-append'');end;load ppp;delete ppp.mat'];
    labelStr='var';
    varHndl=uicontrol( ...
        'Style','push', ...
        'Enable','off',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,.1,.05,0.05], ...
        'String',labelStr, ...
        'Callback',call);
    
    % The FILE button
    labelStr='file';
    call=['load v; uisave(varNames,''data_ks'')'];
    fileHndl=uicontrol( ...
        'Style','push', ...
        'Enable','off',...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.93,.1,.05,0.05], ...
        'String',labelStr, ...
        'Callback',call);
    
    % The CLOSE button
    labelStr='Close';
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.88,.03,.1,0.05], ...
        'String',labelStr, ...
        'Callback',callbackStr);
    
    % The Print button
    labelStr='P';
    call1='load v;load w;figure;plot(X,y,''x'');hold on;';
    call2='if ff==1 fplot(f,[nX mX],rr);end;str=who(''-file'',''w'');';
    call3='if max(strcmp(str,''yy'')) xx=trans(xp,nX,mX);plot(xx,yy,''r'');end;hold off;';
    call4='if max(strcmp(str,''yyd'')) if ~isempty(yyd) hold on;';
    call5='plot(X,yyd,''g:'',X,yyh,''g:'');end;end;hold off;';
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.001,.96,.03,0.035], ...
        'String',labelStr, ...
        'Callback',[call1,call2,call3,call4,call5]);
    
    % The INTERV.SPOL. button
    labelStr='conf. int.';
    call1='load v;load w;hold on;if ff==0 f=C;end;[yyd,yyh]=intsp(x,y,n,k,m,h,.05,S,f,C);';
    call2='hold off;save w yyd yyh -append;';
    intHndl=uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.77,.96,.09,0.035], ...
        'Enable','off',...
        'String',labelStr, ...
        'Callback',[call1,call2]);
    hndlList=[nwHndl,nwcycHndl,llHndl,llcycHndl,gmHndl,gmcycHndl,...
        pchHndl,pchcycHndl,intHndl,nwLHndl,nwRHndl,llLHndl,llRHndl,...
        gmLHndl,gmRHndl,pchLHndl,pchRHndl,varHndl,fileHndl];
    set(gcf,'UserData',hndlList);
    %set(C,'Position',[0 0.0347 1.0000 0.9190]);
    set(C,'Position',[0.1059 0.1655 0.7700 0.6898]);
    %set(C,'Position',[1 1 .97 .9].*scrsz+[.01 .012 0 0]);
    
end
